﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HoangPhap.Data;

namespace HoangPhap.Bussiness
{
    public class ArticleCategories
    {
        public int DeleteById(int id)
        {
            return new HoangPhapDataContext().CallArticleCategoriesDeleteById(id);
        }

        public int DeleteDynamic(string whereCondition)
        {
            return new HoangPhapDataContext().CallArticleCategoriesDeleteDynamic(whereCondition);
        }

        public int Insert(System.Boolean isDisplayInMenu, System.Int32 order, System.Int32 status, 
            System.Boolean isLocked, System.Int32 parrentId, System.DateTime createdDate, 
            System.DateTime updatedDate, System.Int32 editorId, ref System.Int32 id)
        {
            return new HoangPhapDataContext().CallArticleCategoriesInsert(isDisplayInMenu, order, status, isLocked,
                parrentId, createdDate,
                updatedDate, editorId, ref id);
        }

        public int InsertUpdate(System.Int32 id, System.Boolean isDisplayInMenu, System.Int32 order, 
            System.Int32 status, System.Boolean isLocked, System.Int32 parrentId, System.DateTime createdDate, 
            System.DateTime updatedDate, System.Int32 editorId)
        {
            return new HoangPhapDataContext().CallArticleCategoriesInsertUpdate(id, isDisplayInMenu, order,
                status, isLocked, parrentId, createdDate, updatedDate, editorId);
        }

        public int Update(System.Int32 id, System.Boolean isDisplayInMenu, System.Int32 order, 
            System.Int32 status, System.Boolean isLocked, System.Int32 parrentId, System.DateTime createdDate, 
            System.DateTime updatedDate, System.Int32 editorId)
        {
            return new HoangPhapDataContext().CallArticleCategoriesUpdate(id, isDisplayInMenu, order,
                status, isLocked, parrentId, createdDate, updatedDate, editorId);
        }

        public List<EntityClasses.ArticleCategory> SelectAll()
        {
            var lst = new List<EntityClasses.ArticleCategory>();
            var ct = new HoangPhapDataContext().GetArticleCategoriesSelectAllResults();
            if (ct.Rows.Count > 0)
            {
                lst.AddRange(from DataRow dt in ct.Rows
                             select new EntityClasses.ArticleCategory
                             {
                                 Id = Convert.ToInt32(dt["ID"].ToString()),
                                 Order = Convert.ToInt32(dt["Order"].ToString()),
                                 CreatedDate = Convert.ToDateTime(dt["CreatedDate"].ToString()),
                                 EditorId = Convert.ToInt32(dt["EditorId"].ToString()),
                                 Status = Convert.ToInt32(dt["Status"].ToString()),
                                 UpdatedDate = Convert.ToDateTime(dt["UpdatedDate"].ToString()),
                                 IsDisplayInMenu = Convert.ToBoolean(dt["IsDisplayInMenu"].ToString()),
                                 IsLocked = Convert.ToBoolean(dt["IsLocked"].ToString()),
                                 ParrentId = Convert.ToInt32(dt["ParrentId"].ToString())
                             });
            }
            return lst;
        }

        public EntityClasses.ArticleCategory SelectById(int id)
        {
            var lst = new EntityClasses.ArticleCategory();
            var ct = new HoangPhapDataContext().GetArticleCategoriesSelectByIdResults(id);
            if (ct.Rows.Count <= 0) return lst;

            lst = new EntityClasses.ArticleCategory
            {
                Id = Convert.ToInt32(ct.Rows[0]["ID"].ToString()),
                Order = Convert.ToInt32(ct.Rows[0]["Order"].ToString()),
                CreatedDate = Convert.ToDateTime(ct.Rows[0]["CreatedDate"].ToString()),
                EditorId = Convert.ToInt32(ct.Rows[0]["EditorId"].ToString()),
                Status = Convert.ToInt32(ct.Rows[0]["Status"].ToString()),
                UpdatedDate = Convert.ToDateTime(ct.Rows[0]["UpdatedDate"].ToString()),
                IsDisplayInMenu = Convert.ToBoolean(ct.Rows[0]["IsDisplayInMenu"].ToString()),
                IsLocked = Convert.ToBoolean(ct.Rows[0]["IsLocked"].ToString()),
                ParrentId = Convert.ToInt32(ct.Rows[0]["ParrentId"].ToString())
            };
            return lst;
        }
    }
}
